#pragma once
#include <iostream>
#include <string>

enum
{
    DIVCODE = 1, // 除0错误
    MODCODE,     // 模0错误
    UNDOWN
};

const std::string oper = "+-*/%";

class Task
{
public:
    Task(){};

    Task(int a, int b, char op)
        : a_(a), b_(b), op_(op), result_(0), exitcode_(0)
    {
    }

    void run()
    {
        switch (op_)
        {
        case '+':
            result_ = a_ + b_;
            break;
        case '-':
            result_ = a_ - b_;
            break;
        case '*':
            result_ = a_ * b_;
            break;
        case '/':
            if (b_ == 0)
                exitcode_ = DIVCODE;
            result_ = a_ / b_;
            break;
        case '%':
            if (b_ == 0)
                exitcode_ = MODCODE;
            result_ = a_ / b_;
            break;
        default:
            exitcode_ = UNDOWN;
            break;
        }
    }

    std::string result()
    {
        std::string left = std::to_string(a_) + " " + op_+ " "+std::to_string(b_) + " =";
        std::string right = " " + std::to_string(result_) + ",exitcode = " + std::to_string(exitcode_);
        std::string ret = left + right;

        return ret;
    }

    std::string display()
    {
        std::string ret = std::to_string(a_) + " " +op_+" "+std::to_string(b_) + " = ? ";
        return ret;
    }

private:
    int a_;
    int b_;
    char op_;

    int result_;
    int exitcode_;
};